package org.jeecg.modules.manage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.manage.entity.CaishuiRefundRecord;
import org.jeecg.modules.manage.service.IMCaishuiRefundRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 退款记录[管理]
 * @Author: yfkj
 * @Date: 2023-04-10
 * @Version: V1.0
 */
@Api(tags = "退款记录[管理]")
@RestController
@RequestMapping("/manageApi/caishuiRefundRecord")
@Slf4j
public class MCaishuiRefundRecordController extends JeecgController<CaishuiRefundRecord, IMCaishuiRefundRecordService> {

    @Autowired
    private IMCaishuiRefundRecordService imCaishuiRefundRecordService;


    /**
     * 分页列表查询
     *
     * @param caishuiRefundRecord
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "退款记录[管理]-分页列表查询", notes = "退款记录[管理]-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CaishuiRefundRecord>> queryPageList(CaishuiRefundRecord caishuiRefundRecord,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            HttpServletRequest req) {
        QueryWrapper<CaishuiRefundRecord> queryWrapper = QueryGenerator.initQueryWrapper(caishuiRefundRecord, req.getParameterMap());
        Page<CaishuiRefundRecord> page = new Page<CaishuiRefundRecord>(pageNo, pageSize);
        IPage<CaishuiRefundRecord> pageList = imCaishuiRefundRecordService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 查询退款结果
     * @param yurRef
     * @return
     */
    @RequestMapping(value = "/queryRefundResult", method = RequestMethod.GET)
    public Result<?> queryRefundResult(@RequestParam(name = "yurRef", required = true) String yurRef) {
        return imCaishuiRefundRecordService.queryRefundResult(yurRef);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param caishuiRefundRecord
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CaishuiRefundRecord caishuiRefundRecord) {
        return super.exportXls(request, caishuiRefundRecord, CaishuiRefundRecord.class, "退款记录[管理]");
    }

}
